Title: SQL W3S (By-BKK) / 122 MySQL Functions
Tags: Obsidian_to_Anki

Q: What does the MySQL ASCII() function do?
A: It returns the ASCII value for a specific character

Q: What does CHAR_LENGTH() return in MySQL?
A: The length of a string in characters

Q: What does CONCAT() do in MySQL?
A: It adds two or more expressions together

Q: What is the use of CONCAT_WS() in MySQL?
A: Adds two or more expressions together with a separator

Q: What does FIELD() function do in MySQL?
A: Returns the index position of a value in a list of values

Q: What does FIND_IN_SET() return in MySQL?
A: Returns the position of a string within a list of strings

Q: What does FORMAT() do in MySQL?
A: Formats a number with commas and decimals, rounded to a specified number of decimal places

Q: What is the role of INSERT() in MySQL string functions?
A: Inserts a string within another string at a specified position for a certain number of characters

Q: What does INSTR() return in MySQL?
A: Returns the position of the first occurrence of a string inside another string

Q: What does LCASE() do in MySQL?
A: Converts a string to lower-case

Q: What does LEFT() extract in MySQL strings?
A: A number of characters from a string, starting from the left

Q: What is measured by LENGTH() in MySQL?
A: The length of a string in bytes

Q: How does LOCATE() function work in MySQL?
A: Returns the position of the first occurrence of a substring in a string

Q: What does LOWER() do in MySQL?
A: Converts a string to lower-case

Q: Why use LPAD() in MySQL?
A: Left-pads a string with another string to a certain length

Q: What does LTRIM() do to a string in MySQL?
A: Removes leading spaces from a string

Q: What is the purpose of MID() in MySQL?
A: Extracts a substring from a string starting at any position

Q: How does POSITION() help in MySQL?
A: Returns the position of the first occurrence of a substring in a string

Q: What does REPEAT() do in MySQL?
A: Repeats a string a specified number of times

Q: How does REPLACE() help in MySQL?
A: Replaces all occurrences of a substring in a string with a new substring

Q: What is REVERSE() used for in MySQL?
A: It reverses a string and returns the result

Q: What does RIGHT() extract from a string in MySQL?
A: A number of characters from the right side of a string

Q: Why use RPAD() with MySQL strings?
A: Right-pads a string with another string to a certain length

Q: What does RTRIM() do in MySQL?
A: Removes trailing spaces from a string

Q: What does SPACE() return in MySQL?
A: Returns a string with a specified number of space characters

Q: What is STRCMP() used for in MySQL?
A: Compares two strings

Q: How does SUBSTR() work in MySQL?
A: Extracts a substring from any position in a string

Q: What can SUBSTRING() do in MySQL?
A: Extracts a substring from any position in a string

Q: What does SUBSTRING_INDEX() return?
A: Returns a substring before a specified number of delimiter occurrences

Q: What does TRIM() do to a string in MySQL?
A: Removes leading and trailing spaces from a string

Q: How does UCASE() work in MySQL?
A: Converts a string to upper-case

Q: What does UPPER() do in MySQL?
A: Converts a string to upper-case

Q: Does CHAR_LENGTH() measure string bytes? True/False
A: False

Q: Does LENGTH() measure bytes of a string in MySQL? True/False
A: True

Q: Returns the position of a substring in a string
A: LOCATE(), POSITION(), INSTR()

Q: Returns length of a string in characters
A: CHAR_LENGTH(), CHARACTER_LENGTH()

Q: Returns length of a string in bytes
A: LENGTH()

Q: What does ABS() return in MySQL?
A: The absolute value of a number

Q: What is ACOS() used for in MySQL?
A: Returns the arc cosine of a number

Q: How does ASIN() work in MySQL?
A: Returns the arc sine of a number

Q: What does ATAN() return in MySQL?
A: Returns the arc tangent of one or two numbers

Q: How is ATAN2() used in MySQL?
A: Returns the arc tangent of two numbers

Q: What does AVG() calculate in MySQL?
A: The average value of an expression

Q: What does CEIL() or CEILING() do in MySQL?
A: Returns the smallest integer greater than or equal to a number

Q: What function returns cosine in MySQL?
A: COS()

Q: Which function gives the cotangent of a number?
A: COT()

Q: What does COUNT() return in MySQL?
A: The number of records returned by a select query

Q: How is DEGREES() used in MySQL?
A: Converts a value in radians to degrees

Q: What does DIV do in MySQL numeric functions?
A: Performs integer division

Q: What does EXP() return in MySQL?
A: Returns e raised to the power of a specified number

Q: What does FLOOR() return in MySQL?
A: Returns the largest integer value less than or equal to a number

Q: Which function gets the greatest value in MySQL?
A: GREATEST()

Q: How to get the smallest value in MySQL?
A: LEAST()

Q: What does LN() return in MySQL?
A: The natural logarithm of a number

Q: What is the use of LOG() in MySQL?
A: Returns the natural logarithm of a number or the logarithm to a specified base

Q: What does LOG10() return in MySQL?
A: Natural logarithm of a number to base 10

Q: What does LOG2() return?
A: Natural logarithm of a number to base 2

Q: What does MAX() give in MySQL?
A: Maximum value in a set

Q: What does MIN() return in MySQL?
A: Minimum value in a set

Q: What is retrieved by MOD() in MySQL?
A: The remainder of a number divided by another number

Q: What does PI() return in MySQL?
A: The value of PI

Q: What is POW() or POWER() used for in MySQL?
A: Returns a number raised to the power of another number

Q: How does RADIANS() work in MySQL?
A: Converts degrees to radians

Q: Which function generates a random number?
A: RAND()

Q: What does ROUND() do in MySQL?
A: Rounds a number to specified decimal places

Q: What does SIGN() return in MySQL?
A: The sign of a number

Q: What does SIN() return in MySQL?
A: The sine of a number

Q: What does SQRT() give in MySQL?
A: Square root of a number

Q: What does SUM() do in MySQL?
A: Calculates the sum of values

Q: What does TAN() return in MySQL?
A: The tangent of a number

Q: How does TRUNCATE() work in MySQL?
A: Truncates a number to specified decimal places

Q: How does ADDDATE() work in MySQL?
A: Adds a date/time interval to a date and returns the result

Q: What does ADDTIME() do in MySQL?
A: Adds a time interval to a time/datetime and returns the result

Q: What does CURDATE() return?
A: Current date

Q: What does CURRENT_DATE() or CURRENT_TIME() return?
A: Current date or current time

Q: What does CURRENT_TIMESTAMP() give in MySQL?
A: Current date and time

Q: What is the output of CURTIME() in MySQL?
A: Current time

Q: How does DATE() work in MySQL?
A: Extracts the date part from a datetime

Q: What does DATEDIFF() return in MySQL?
A: Number of days between two date values

Q: How does DATE_ADD() work?
A: Adds a time/date interval to a date

Q: What does DATE_FORMAT() do?
A: Formats a date

Q: How does DATE_SUB() work in MySQL?
A: Subtracts a time/date interval from a date

Q: What does DAY() return for a date?
A: Day of the month

Q: What does DAYNAME() return for a date in MySQL?
A: Weekday name for the date

Q: Which function gets the month from a date?
A: MONTH()

Q: What does MONTHNAME() return for a date?
A: Name of the month

Q: What is NOW() used for in MySQL?
A: Returns the current date and time

Q: How does PERIOD_ADD() work in MySQL?
A: Adds specified number of months to a period

Q: What is PERIOD_DIFF() in MySQL?
A: Returns the difference between two periods

Q: What does QUARTER() return for a date?
A: Quarter of the year

Q: What does SECOND() extract from a time/datetime in MySQL?
A: Second part

Q: How does SEC_TO_TIME() function work?
A: Returns a time value based on specified seconds

Q: How does STR_TO_DATE() operate in MySQL?
A: Returns a date based on a string and a format

Q: What does SUBDATE() do in MySQL?
A: Subtracts a date/time interval from a date and returns the result

Q: What does SUBTIME() do?
A: Subtracts a time interval from a datetime and returns the result

Q: What does SYSDATE() return in MySQL?
A: Current date and time

Q: What does TIME() function extract?
A: Time part from a given time/datetime

Q: What does TIME_FORMAT() do in MySQL?
A: Formats a time string

Q: How do you convert time to seconds?
A: Use TIME_TO_SEC()

Q: How does TIMEDIFF() operate?
A: Returns the difference between two time/datetime values

Q: What does TIMESTAMP() do in MySQL?
A: Returns a datetime value based on a date or datetime value

Q: How does TO_DAYS() function work?
A: Returns the number of days between a date and "0000-00-00"

Q: What is WEEK() used for in MySQL?
A: Returns the week number for a given date

Q: What does WEEKDAY() return in MySQL?
A: Weekday number for a given date

Q: What does WEEKOFYEAR() return?
A: Week number for a given date

Q: What does YEAR() extract from a date?
A: Year part

Q: What does YEARWEEK() do in MySQL?
A: Returns year and week number for a given date

Q: What does BIN() function return?
A: Binary representation of a number

Q: How does BINARY() convert values?
A: To a binary string

Q: Why use CASE in MySQL?
A: Goes through conditions and returns a value when the first condition is met

Q: What does CAST() do in MySQL?
A: Converts a value to a specified datatype

Q: What does COALESCE() return in MySQL?
A: First non-null value in a list

Q: What is CONNECTION_ID() used for?
A: Returns the unique connection ID for the current connection

Q: How does CONV() help in MySQL?
A: Converts a number from one base system to another

Q: What does CONVERT() do in MySQL?
A: Converts a value to specified datatype or character set

Q: What does CURRENT_USER() return?
A: User name and host name for the current MySQL account

Q: What does DATABASE() function return?
A: Name of the current database

Q: How does IF() function help in MySQL?
A: Returns one value if condition is TRUE, another value if FALSE

Q: What is IFNULL() used for in MySQL?
A: Returns specified value if expression is NULL, else returns the expression

Q: What does ISNULL() return in MySQL?
A: 1 if the expression is NULL, else 0

Q: What does LAST_INSERT_ID() provide?
A: AUTO_INCREMENT ID of the last inserted row

Q: When does NULLIF() return NULL?
A: When two expressions are equal

Q: What does SESSION_USER() return?
A: Current MySQL user name and host name

Q: What is SYSTEM_USER() in MySQL?
A: Current MySQL user name and host name

Q: How does USER() function work in MySQL?
A: Current MySQL user name and host name

Q: What does VERSION() return in MySQL?
A: Current version of MySQL database

Q: Returns a string's length in bytes
A: LENGTH()

Q: Current database name in MySQL
A: DATABASE()

Q: First non-null value in a list
A: COALESCE()

Q: Compares two expressions and gives NULL if equal
A: NULLIF()